public class CompressString {
    public String compressString (String param) {
        // write code here
        StringBuilder ret = new StringBuilder();
        int index = 0;
        char[] c = param.toCharArray();
        while (index < c.length) {
            char tmp = c[index];
            int count = 0;
            while (index < c.length && c[index] == tmp) {
                index++;
                count++;
            }
            ret.append(tmp);
            if (count != 1) {
                ret.append(count);
            }
        }
        return ret.toString();
    }
}
